<template>
  <section class="webview fixHeight">
    <el-scrollbar style="height:100%">
      <el-form ref="form" :model="detail" label-width="100px" class="form">
        <el-form-item label="城市">
          <el-input v-model="detail.regionId" />
        </el-form-item>
        <el-form-item label="二手房房价">
          <el-input v-model="detail.secondPrice" />
        </el-form-item>
        <el-form-item label="新房房价">
          <el-input v-model="detail.enterpriseId" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit">提交</el-button>
          <el-button @click="cancel">返回</el-button>
        </el-form-item>
      </el-form>
    </el-scrollbar>
  </section>
</template>
<script>
import { houareaAdd } from '@/api/api'
export default {
  data() {
    return {
      fileList: [],
      detail: {
        'newPrice': '0',
        'regionId': '',
        'regionName': '',
        'secondPrice': ''
      }
    }
  },
  created() {
    if (this.$route.query.id) {
      shopDetail(this.$route.query.id).then(({ data }) => {
        this.detail = data
        this.fileList[0] = this.detail.logo
      })
    }
  },
  methods: {
    handleRemove(index) {
      this.fileList.splice(index, 1)
    },
    // 上传图片之前的验证
    handleUpload() {
    },
    // 上传成功之后的回调
    handleSuccess(res) {
      if (res.code === 200) {
        this.fileList.push(res.data)
        this.detail.logo = this.fileList[0]
      }
    },
    // 添加/编辑
    submit() {
      // 验证不通过则不提交
      if (!this.vertify()) {
        return false
      }
      if (this.$route.query.id) {
        // 编辑
        shopUpdate(this.detail).then(data => {
          Is.tip('编辑成功', 2000, 'success')
          this.$router.back()
        })
      } else {
        // 新增
        houareaAdd(this.detail).then(data => {
          Is.tip('添加成功', 2000, 'success')
          this.$router.back()
        })
      }
    },
    // 返回
    cancel() {
      this.$router.back()
    },
    vertify() {
      // if (Is.empty(this.detail.title)) {
      //   Is.tip('请输入标题')
      //   return false
      // }
      return true
    }
  }}
</script>
